﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;

namespace Txt2Shp4Sharp.lib
{
    public class XmlFiles : XmlDocument
    {
        private string _xmlFileName;
        public string XmlFileName
        {
            get { return _xmlFileName; }
            set { _xmlFileName = value; }
        }

        public XmlFiles(string xmlFile)
        {
            XmlFileName = xmlFile;
            this.Load(xmlFile);
        }

        /// <summary>
        /// 给定一个节点的xmlFath表达式并返回一个节点
        /// </summary>
        /// <param name="xmlFath"></param>
        /// <returns></returns>
        public XmlNode FindNode(string xmlFath)
        {
            XmlNode xmlNode = this.SelectSingleNode(xmlFath);
            return xmlNode;
        }

        /// <summary>
        /// 给定一个节点的xmlFath表达式返回其值
        /// </summary>
        /// <param name="xmlPath"></param>
        /// <returns></returns>
        public string GetNodeValue(string xmlPath)
        {
            XmlNode xmlNode = this.SelectSingleNode(xmlPath);
            return xmlNode.InnerText;
        }

        /// <summary>
        /// 给定一个节点的表达式返回此节点下的孩子节点列表
        /// </summary>
        /// <param name="xmlPath"></param>
        /// <returns></returns>
        public XmlNodeList GetNodeList(string xmlPath)
        {
            XmlNodeList nodeList = this.SelectSingleNode(xmlPath).ChildNodes;
            return nodeList;
        }
    }
}
